package com.xjj.datarources.service.impl;

import com.xjj.datarources.service.MQService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @name: xjj
 * @date: 2021/6/2 13:14
 */
@Service
public class MQServiceImpl implements MQService {

/*    @Resource
    private RabbitMessagingTemplate rabbitMessagingTemplate;*/


    @Resource
    private RabbitTemplate rabbitTemplate;


    @Override
    public void sendWork() {
        //填写三个参数
        //rabbitMessagingTemplate.convertAndSend("queue_work", "时间："+System.currentTimeMillis());
        Map<String, Object> data = new HashMap<>();
        data.put("code", 200);
        data.put("msg", "sb");
        data.put("createTime", new Date());
        //Object payload;
        rabbitTemplate.convertAndSend("topic_exchange", "topic.work2", data);
        //rabbitTemplate.convertAndSend("direct_exchange","topic.work2", data);
        //rabbitTemplate.convertAndSend("direct_exchange","direct.work", data);
        //rabbitMessagingTemplate.
    }


    @Override
    public void sendTopic() {
        Map<String, Object> data = new HashMap<>();
        data.put("code", 200);
        data.put("msg", "sb");
        data.put("createTime", new Date());
        //Object payload;
        //rabbitTemplate.convertAndSend("topic_exchange", "topic.work2", data);
        rabbitTemplate.convertAndSend("topic_exchange","topic.work3", data);
    }
}
